<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>确认订单</title>
    <script src="/public/sp/js/mui.min.js"></script>
    <link href="/public/sp/css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/public/sp/css/style.css" />
    <link rel="stylesheet" href="/public/sp/css/iconfont.css" />
    <link rel="stylesheet" href="/public/sp/css/shoupiao.css" />
</head>
<body>
	<header class="mui-bar mui-bar-nav">
	    <h1 class="mui-title">微信购票</h1>
	</header>
	<div class="mui-content gp_content" style="height: 100%;">
	    <div class="gp_conbox" style="height: 100%;">
	    	<div class="qr_top">
	    		<p><img src="/public/sp/images/bac_qrdd.jpg"></p>
	    		<div class="qr_nr">
	    			<p class="bt">票价金额</p>
	    			<div class="pribox">
	    				<div class="left">¥<em>{$ticket_config['ticket_price']}</em></div>
	    				<div class="right">
	    					<div class="mui-numbox">
								<button class="mui-btn mui-btn-numbox-minus" type="button"></button>
								<input id="nums" name="nums" class="mui-input-numbox" value="1" readonly="readonly" type="number" />
								<button class="mui-btn mui-btn-numbox-plus" type="button"></button>
							</div>
	    				</div>
	    			</div>
	    		</div>
	    	</div>
	    	<div class="sjpri">总金额：¥<em id="total_price">{$ticket_config['ticket_price']}</em></div>
	    	<div class="qr_btn"><a href="javascript:buy();"><img src="/public/sp/images/bt_zf.jpg"></a></div>
	    </div>
	</div>
	{include file="bottom" /}
</body>
<script src="/public/static/js/jquery.min.js"></script>
<script src="/public/static/layui/layui.all.js"></script>
<script>
	$('#nums').change(function(){
		var nums=$(this).val();
		if(nums<1){
			$(this).val(1);
		}else{
			var total=parseFloat("{$ticket_config['ticket_price']}")*nums;
			$("#total_price").text(total);
		}
	})
	function buy(){
		$.ajax({
			type:"post",
			data:{
				nums:$("#nums").val()
			},
			url:"/index/payment/buy_mticket",
			success:function(data){
				data=JSON.parse(data);
				callpay(data);
			}
		});
	}
	//调用微信JS api 支付
		function jsApiCall(jsApiParameters) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
				function(res) {
					if(res.err_msg == "get_brand_wcpay_request:ok") {
						alert('支付成功');
					} else {
						alert('支付失败');
					}
					window.location="/index/index/my_tickets";
				}
			);
		}

		function callpay(jsApiParameters) {
			if(typeof WeixinJSBridge == "undefined") {
				if(document.addEventListener) {
					document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
				} else if(document.attachEvent) {
					document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
				}
			} else {
				jsApiCall(jsApiParameters);
			}
		}
</script>
</html>
